from django.contrib.auth.models import Permission, Group
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response

from meiduo_admin.serialziers.group import GroupSerializer
from meiduo_admin.serialziers.permission import PermissionSerializer
from users.models import User
from rest_framework.viewsets import ModelViewSet

from meiduo_admin.serialziers.admin import AdminSerializer
from meiduo_admin.utils.page import PageNum


class AdminView(ModelViewSet):
    permission_classes = [IsAdminUser, ]
    serializer_class = AdminSerializer
    # 获取管理员
    queryset = User.objects.filter(is_staff=True)
    pagination_class = PageNum

    def simple(self, request):
        """
        获取分组数据
        :param request:
        :return:
        """
        # 查询权限表
        data = Group.objects.all()

        # 返回权限数据
        ser = GroupSerializer(data, many=True)
        return Response(ser.data)
